# Copyright (C) 2011 clueless <clueless.mmopeon@gmail.com>
#
# This file is part of MMO Peon.
#
# MMO Peon is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# MMO Peon is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MMO Peon.  If not, see <http://www.gnu.org/licenses/>.

.global _SendHookStub, _RecvHookStub
.extern _originalSendFunction, _originalRecvFunction, _SendHook, _RecvHook
.text

_SendHookStub:
    pushal                                  # ESP changes by 0x20 bytes
    mov         0x28(%esp), %eax            # Arg2 (size)
    mov         0x2C(%esp), %ecx            # Arg3 (buffer)
    push        %eax
    push        %ecx
    call        _SendHook@8
    popal
    movl        0x04(%esp), %eax            # Original instructions
    sub         $0x0C, %esp                 # ...
    jmp         *(_originalSendFunction)    # and continue with the actual send function

_RecvHookStub:
    pushal
    push        %edi
    push        %ebp
    call        _RecvHook@8
    popal

    mov         0x28(%esp), %eax            # Original instructions
    movzbl      0x05(%eax), %ecx            # ...
    jmp         *(_originalRecvFunction)    # continue with actual receive
